home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Magazine / C_Tutorial / Part-13 / PatchLib / source / Funcs.asm < prev    next >
Encoding:
Assembly Source File  |  1997-12-10  |  28.0 KB  |  1,169 lines

  1.     incdir "Include:"
  2.     include "exec/types.i"
  3.     include "exec/execbase.i"
  4.     include "exec/tasks.i"
  5.     include "exec/memory.i"
  6.  
  7.  
  8.     include "include/PRIVATE/ASMMacros.i"
  9.     include "include/PRIVATE/patch.i"
  10.     include "include/PRIVATE/patchbase.i"
  11.  
  12.  
  13. AllocMem    set    -198
  14. FreeMem        set    -210
  15. Forbid        set    -132
  16. Permit        set    -138
  17. Disable        set    -120
  18. Enable        set    -126
  19. FindName    set    -276
  20. FindTask    set    -294
  21.  
  22. MatchPatternNoCase    set    -972    ;V37
  23. MatchPattern        set    -846    ;V37
  24. StackSwap        set    -732    ;V37
  25.  
  26.  
  27. PatchFreeVec    set    -84    ;patch
  28.  
  29.     XREF _PatchMatch
  30.  
  31.  
  32. ;**************************************************
  33.     SECTION code
  34.  
  35. ; -------------------------------------------------------------------------------
  36. ;PCODE_START:
  37. PatchCode6Start:
  38.     dc.l 0
  39. PatchCode6PatchStruct:
  40.     dc.l 0
  41. PatchCode6Stack:
  42.     dc.l 0
  43.     dc.l 0
  44.     dc.l 0
  45.     dc.l 0
  46.  
  47. PC6Offset_Add = *-PatchCode6Start
  48.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  49.  
  50. PC6Offset_Stack1_Tst = *-PatchCode6Start
  51.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  52.     beq.s PatchCode6_Stack1_Skip
  53.  
  54.     movem.l d0-d2/a0-a1/a6,-(a7)
  55. ;    movem.l d0-d2/a0-a2/a6,-(a7)
  56.     move.l PatchCode6PatchStruct(pc),a0
  57.     move.l PatchCode6Stack(pc),d0
  58.     jsr PatchLibraryStackAlloc.L    ;keeps OMA from optimizing this to bsr
  59. ;    movem.l (a7)+,d0-d2/a0-a2/a6
  60.     movem.l (a7)+,d0-d2/a0-a1/a6
  61.  
  62. PatchCode6_Stack1_Skip:
  63. PC6Offset_Sub = *-PatchCode6Start
  64.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  65. PC6Offset_JmpNext = *-PatchCode6Start
  66.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  67.  
  68. PatchCode6End:
  69. ; -------------------------------------------------------------------------------
  70. ;PCODE_ORIG
  71. PatchCode7Start:
  72.     dc.l 0
  73.     dc.l 0
  74.     dc.l 0
  75. PC7Offset_Disable = *-PatchCode7Start
  76.     dc.l 0
  77.     dc.l 0
  78.     dc.l 0
  79. PC7Offset_Add = *-PatchCode7Start
  80.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  81. PC7Offset_Tst0 = *-PatchCode7Start
  82.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  83.     bne PatchCode7Skip3        ;Disabled ?
  84.  
  85. PC7Offset_Jsr = *-PatchCode7Start
  86.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  87.  
  88. PatchCode7Skip3:
  89. PC7Offset_Sub = *-PatchCode7Start
  90.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  91. PC7Offset_JmpNext = *-PatchCode7Start
  92.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  93. PatchCode7End:
  94. ; -------------------------------------------------------------------------------
  95. ;PCODE_GENERIC
  96. PatchCodeStart:
  97. PatchCodePatchStruct:
  98. PC2Offset_PatchXResult = *-PatchCodeStart
  99.     dc.l    0            ;TRUE, if PatchXResult system is used
  100. PC2Offset_PatchStruct = *-PatchCodeStart
  101.     dc.l    0            ;Pointer to PatchStruct
  102. PC2Offset_Stack = *-PatchCodeStart
  103.     dc.l    0            ;Stacksize required to execute the patchcode
  104. PC2Offset_Disable = *-PatchCodeStart
  105.     dc.l    0            ;Disable nesting counter 0= Enabled
  106. PatchCodeList:
  107. PC2Offset_List = *-PatchCodeStart
  108.     dc.l    0            ;Exclude/Include List
  109. PC2Offset_Usage = *-PatchCodeStart
  110.     dc.l    0            ;Usage Counter
  111. PatchCode:
  112. PC2Offset_Add = *-PatchCodeStart
  113.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  114. PC2Offset_Tst0 = *-PatchCodeStart
  115.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  116.     bne PatchCodeSkip3        ;Disabled ?
  117.  
  118. PC2Offset_Tst = *-PatchCodeStart
  119.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  120.     beq.s PatchCodeSkip1
  121.  
  122.     movem.l d0/d1/a0/a1,-(sp)
  123.     move.l PatchCodeList(pc),a0
  124.     jsr _PatchMatch.L
  125.     tst.l d0
  126.     movem.l (sp)+,d0/d1/a0/a1
  127.     bne.s PatchCodeSkip2
  128.  
  129. PatchCodeSkip1:
  130.     move.l #1,-(sp)
  131.  
  132. PC2Offset_Jsr = *-PatchCodeStart
  133.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  134.     tst.l (a7)+
  135. PC2Offset_bne = *-PatchCodeStart
  136.     bne.s PatchCodeSkip
  137.  
  138.     addq.l #4,a7
  139. PC2Offset_Tst1_XResult = *-PatchCodeStart
  140.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  141.     beq.s PatchCode_XResult1_Skip
  142.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  143.  
  144.  
  145. PatchCodeSkip2:
  146. PatchCode_XResult1_Skip:
  147. PC2Offset_Sub = *-PatchCodeStart
  148.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  149. PC2Offset_JmpOrig = *-PatchCodeStart
  150.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  151.  
  152. PatchCodeSkip:
  153. PC2Offset_Tst2_XResult = *-PatchCodeStart
  154.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  155.     beq.s PatchCode_XResult2_Skip
  156.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  157.     bne.s PatchCodeSkip2
  158.  
  159.  
  160. PatchCode_XResult2_Skip:
  161. PatchCodeSkip3:
  162. PC2Offset_Sub2 = *-PatchCodeStart
  163.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  164. PC2Offset_SystemEntry = *-PatchCodeStart
  165. PC2Offset_JmpNext= *-PatchCodeStart
  166.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  167. PatchCodeEnd:
  168. ; -------------------------------------------------------------------------------
  169. ;PCODE_USER0
  170. PatchCode10Start:
  171.     dc.l    0
  172.     dc.l    0            ;Pointer to PatchStruct
  173.     dc.l    0            ;Stacksize required to execute the patchcode
  174.     dc.l    0            ;Disable nesting counter 0= Enabled
  175. PatchCode10List:
  176.     dc.l    0            ;Exclude/Include List
  177.     dc.l    0            ;Usage Counter
  178. PC10Offset_Add = *-PatchCode10Start
  179.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  180. PC10Offset_Tst0 = *-PatchCode10Start
  181.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  182.     bne PatchCode10Skip3        ;Disabled ?
  183.  
  184. PC10Offset_Tst = *-PatchCode10Start
  185.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  186.     beq.s PatchCode10Skip1
  187.  
  188.     movem.l d0/d1/a0/a1,-(sp)
  189.     move.l PatchCode10List(pc),a0
  190.     jsr _PatchMatch.L
  191.     tst.l d0
  192.     movem.l (sp)+,d0/d1/a0/a1
  193.     bne.s PatchCode10Skip2
  194.  
  195. PatchCode10Skip1:
  196.     move.l #1,-(sp)
  197.  
  198. PC10Offset_Jsr = *-PatchCode10Start
  199.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  200.     tst.l (a7)+
  201.     bne.s PatchCode10Skip
  202.  
  203.     addq.l #4,a7
  204.  
  205. PatchCode10Skip2:
  206. PC10Offset_Sub = *-PatchCode10Start
  207.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  208. PC10Offset_JmpOrig = *-PatchCode10Start
  209.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  210.  
  211. PatchCode10Skip:
  212. PatchCode10Skip3:
  213. PC10Offset_Sub2 = *-PatchCode10Start
  214.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  215. PC10Offset_JmpNext= *-PatchCode10Start
  216.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  217. PatchCode10End:
  218. ; -------------------------------------------------------------------------------
  219. ;PCODE_USER1
  220. PatchCode11Start:
  221.     dc.l    0
  222.     dc.l    0            ;Pointer to PatchStruct
  223.     dc.l    0            ;Stacksize required to execute the patchcode
  224.     dc.l    0            ;Disable nesting counter 0= Enabled
  225. PatchCode11List:
  226.     dc.l    0            ;Exclude/Include List
  227.     dc.l    0            ;Usage Counter
  228. PC11Offset_Add = *-PatchCode11Start
  229.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  230. PC11Offset_Tst0 = *-PatchCode11Start
  231.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  232.     bne PatchCode11Skip3        ;Disabled ?
  233.  
  234. PC11Offset_Tst = *-PatchCode11Start
  235.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  236.     beq.s PatchCode11Skip1
  237.  
  238.     movem.l d0/d1/a0/a1,-(sp)
  239.     move.l PatchCode11List(pc),a0
  240.     jsr _PatchMatch.L
  241.     tst.l d0
  242.     movem.l (sp)+,d0/d1/a0/a1
  243.     bne.s PatchCode11Skip2
  244.  
  245. PatchCode11Skip1:
  246.     move.l #1,-(sp)
  247.  
  248. PC11Offset_Jsr = *-PatchCode11Start
  249.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  250.     tst.l (a7)+
  251.     bne.s PatchCode11Skip
  252.  
  253.     addq.l #4,a7
  254.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  255.  
  256.  
  257. PatchCode11Skip2:
  258. PC11Offset_Sub = *-PatchCode11Start
  259.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  260. PC11Offset_JmpOrig = *-PatchCode11Start
  261.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  262.  
  263.  
  264. PatchCode11Skip:
  265.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  266.     bne.s PatchCode11Skip2
  267.  
  268. PatchCode11Skip3:
  269. PC11Offset_Sub2 = *-PatchCode11Start
  270.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  271. PC11Offset_JmpNext= *-PatchCode11Start
  272.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  273. PatchCode11End:
  274. ; -------------------------------------------------------------------------------
  275. ;PCODE_USER2
  276. PatchCode12Start:
  277.     dc.l    0            ;TRUE, if PatchXResult system is used
  278.     dc.l    0            ;Pointer to PatchStruct
  279.     dc.l    0            ;Stacksize required to execute the patchcode
  280.     dc.l    0            ;Disable nesting counter 0= Enabled
  281. PatchCode12List:
  282.     dc.l    0            ;Exclude/Include List
  283.     dc.l    0            ;Usage Counter
  284. PC12Offset_Add = *-PatchCode12Start
  285.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  286. PC12Offset_Tst0 = *-PatchCode12Start
  287.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  288.     bne PatchCode12Skip3        ;Disabled ?
  289.  
  290. PC12Offset_Tst = *-PatchCode12Start
  291.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  292.     beq.s PatchCode12Skip1
  293.  
  294.     movem.l d0/d1/a0/a1,-(sp)
  295.     move.l PatchCode12List(pc),a0
  296.     jsr _PatchMatch.L
  297.     tst.l d0
  298.     movem.l (sp)+,d0/d1/a0/a1
  299.     bne.s PatchCode12Skip2
  300.  
  301. PatchCode12Skip1:
  302. PC12Offset_Jsr = *-PatchCode12Start
  303.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  304.  
  305. PatchCode12Skip2:
  306. PatchCode12Skip3:
  307. PC12Offset_Sub2 = *-PatchCode12Start
  308.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  309. PC12Offset_JmpNext= *-PatchCode12Start
  310.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  311. PatchCode12End:
  312. ; -------------------------------------------------------------------------------
  313. ;PCODE_USER3
  314. PatchCode13Start:
  315.     dc.l    0
  316.     dc.l    0            ;Pointer to PatchStruct
  317.     dc.l    0            ;Stacksize required to execute the patchcode
  318.     dc.l    0            ;Disable nesting counter 0= Enabled
  319. PatchCode13List:
  320.     dc.l    0            ;Exclude/Include List
  321.     dc.l    0            ;Usage Counter
  322. PC13Offset_Add = *-PatchCode13Start
  323.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  324. PC13Offset_Tst0 = *-PatchCode13Start
  325.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  326.     bne PatchCode13Skip3        ;Disabled ?
  327.  
  328. PC13Offset_Tst = *-PatchCode13Start
  329.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  330.     beq.s PatchCode13Skip1
  331.  
  332.     movem.l d0/d1/a0/a1,-(sp)
  333.     move.l PatchCode13List(pc),a0
  334.     jsr _PatchMatch.L
  335.     tst.l d0
  336.     movem.l (sp)+,d0/d1/a0/a1
  337.     bne.s PatchCode13Skip2
  338.  
  339. PatchCode13Skip1:
  340. PC13Offset_Jsr = *-PatchCode13Start
  341.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  342.  
  343.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  344.  
  345. PatchCode13Skip2:
  346. PatchCode13Skip3:
  347. PC13Offset_Sub2 = *-PatchCode13Start
  348.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  349. PC13Offset_JmpNext= *-PatchCode13Start
  350.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  351. PatchCode13End:
  352. ; -------------------------------------------------------------------------------
  353. ;PCODE_USER4 = PCODE_SYSTEM
  354. PatchCode14Start:
  355.     dc.l    0
  356.     dc.l    0            ;Pointer to PatchStruct
  357.     dc.l    0            ;Stacksize required to execute the patchcode
  358.     dc.l    0            ;Disable nesting counter 0= Enabled
  359. PatchCode14List:
  360.     dc.l    0            ;Exclude/Include List
  361.     dc.l    0            ;Usage Counter
  362. PC14Offset_Add = *-PatchCode14Start
  363.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  364. PC14Offset_Tst0 = *-PatchCode14Start
  365.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  366.     bne PatchCode14Skip3        ;Disabled ?
  367.  
  368. PC14Offset_Tst = *-PatchCode14Start
  369.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  370.     beq.s PatchCode14Skip1
  371.  
  372.     movem.l d0/d1/a0/a1,-(sp)
  373.     move.l PatchCode14List(pc),a0
  374.     jsr _PatchMatch.L
  375.     tst.l d0
  376.     movem.l (sp)+,d0/d1/a0/a1
  377.     bne.s PatchCode14Skip3
  378.  
  379. PatchCode14Skip1:
  380. PC14Offset_Jsr = *-PatchCode14Start
  381.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  382.  
  383. PC14Offset_Sub = *-PatchCode14Start
  384.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  385. PC14Offset_JmpOrig = *-PatchCode14Start
  386.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  387.  
  388. PatchCode14Skip3:
  389. PC14Offset_Sub2 = *-PatchCode14Start
  390.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  391. PC14Offset_SystemEntry = *-PatchCode14Start
  392. PC14Offset_JmpNext= *-PatchCode14Start
  393.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  394. PatchCode14End:
  395. ; -------------------------------------------------------------------------------
  396. ;PCODE_USER5
  397. PatchCode15Start:
  398.     dc.l    0
  399.     dc.l    0            ;Pointer to PatchStruct
  400.     dc.l    0            ;Stacksize required to execute the patchcode
  401.     dc.l    0            ;Disable nesting counter 0= Enabled
  402. PatchCode15List:
  403.     dc.l    0            ;Exclude/Include List
  404.     dc.l    0            ;Usage Counter
  405. PC15Offset_Add = *-PatchCode15Start
  406.     addq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  407. PC15Offset_Tst0 = *-PatchCode15Start
  408.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  409.     bne PatchCode15Skip3        ;Disabled ?
  410.  
  411. PC15Offset_Tst = *-PatchCode15Start
  412.     tst.l $ABABABAB            ;$AB just to fool OMA optimizing
  413.     beq.s PatchCode15Skip1
  414.  
  415.     movem.l d0/d1/a0/a1,-(sp)
  416.     move.l PatchCode15List(pc),a0
  417.     jsr _PatchMatch.L
  418.     tst.l d0
  419.     movem.l (sp)+,d0/d1/a0/a1
  420.     bne.s PatchCode15Skip3
  421.  
  422. PatchCode15Skip1:
  423. PC15Offset_Jsr = *-PatchCode15Start
  424.     jsr $ABABABAB            ;$AB just to fool OMA optimizing
  425.     jsr PatchLibraryXResult.L    ;keeps OMA from optimizing this to bsr
  426.  
  427. PC15Offset_Sub = *-PatchCode15Start
  428.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  429. PC15Offset_JmpOrig = *-PatchCode15Start
  430.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  431.  
  432. PatchCode15Skip3:
  433. PC15Offset_Sub2 = *-PatchCode15Start
  434.     subq.l #1,$ABABABAB        ;$AB just to fool OMA optimizing
  435. PC15Offset_SystemEntry = *-PatchCode15Start
  436. PC15Offset_JmpNext= *-PatchCode15Start
  437.     jmp $ABABABAB            ;$AB just to fool OMA optimizing
  438. PatchCode15End:
  439. ;------------------------------------------------------------------
  440.     XREF _FreeStackCached
  441. PatchCode8Start:
  442.     dc.l 0
  443.     dc.l 0
  444.     dc.l 0
  445.     dc.l 0
  446.     dc.l 0
  447.     dc.l 0
  448.     cmp.l #'PATC',PST_Magic1(a7)
  449.     bne PatchCode8_Stack3_Skip
  450.  
  451.  
  452.     movem.l d0-d1/a0-a2/a6,-(a7)
  453.     lea.l 4*6(a7),a2    ;4Bytes (6 register)
  454.  
  455.     lea.l PST_Magic1(a2),a0
  456.     cmp.l PST_Magic2(a2),a0
  457.     bne PatchLibraryStackFreeSkip1
  458.  
  459.     move.l a2,a0
  460.     move.l PST_OldStack(a2),a1
  461.     move.l -(a0),-(a1)    ;6 registers
  462.     move.l -(a0),-(a1)
  463.     move.l -(a0),-(a1)
  464.     move.l -(a0),-(a1)
  465.     move.l -(a0),-(a1)
  466.     move.l -(a0),-(a1)
  467.  
  468.     move.l sysbase(pc),a6
  469.     lea.l PST_StackSwap(a2),a0
  470.     move.l a1,stk_Pointer(a0)
  471.     CALL StackSwap
  472.  
  473.     move.l a2,a1
  474.     jsr _FreeStackCached
  475.  
  476. PatchLibraryStackFreeSkip1:
  477.     movem.l (a7)+,d0-d1/a0-a2/a6
  478.  
  479. PatchCode8_Stack3_Skip:
  480.     tst.l d0
  481.     rts
  482. PatchCode8End:
  483. ;----------------------------------------------
  484. ;PatchLibraryMatch:
  485. ;a0= Pointer to ListHeader (TaskList)
  486. ;    movem.l d0/d1,-(sp)
  487. ;    jsr _PatchMatch
  488. ;    tst.l d0
  489. ;    movem.l (sp)+,d0/d1
  490. ;    rts
  491.  
  492.  
  493.  
  494. ;    move.l a0,-(sp)
  495. ;
  496. ;    move.l sysbase(pc),a1
  497. ;    move.l ThisTask(a1),a1
  498.  
  499. ;    move.l (a0),a0
  500. ;    tst.l (a0)
  501. ;    beq PatchLibraryMatchListEmpty
  502.  
  503. ;PatchLibraryMatchLoop:
  504. ;    cmp.b #TLI_TYPE_TASKID,LN_TYPE(a0)
  505. ;    bne PatchLibraryMatchLoopSkip1
  506. ;    cmp.l LN_NAME(a0),a1
  507. ;    beq PatchLibraryMatchFound
  508.  
  509. ;PatchLibraryMatchLoopSkip1:
  510. ;    cmp.b #TLI_TYPE_TASKNAME,LN_TYPE(a0)
  511. ;    bne PatchLibraryMatchLoopSkip2
  512.  
  513. ;    movem.l a0/a1,-(sp)
  514. ;    move.l LN_NAME(a0),a0
  515. ;    move.l LN_NAME(a1),a1
  516.  
  517. ;PatchLibraryMatchLoop2:
  518. ;    cmpm.b (a0)+,(a1)+
  519. ;    bne.s PatchLibraryMatchLoop2Skip
  520. ;    tst.b -1(a0)
  521. ;    bne.s PatchLibraryMatchLoop2
  522. ;    movem.l (sp)+,a0/a1
  523. ;    bra PatchLibraryMatchFound
  524. ;PatchLibraryMatchLoop2Skip:
  525. ;    movem.l (sp)+,a0/a1
  526.  
  527. ;PatchLibraryMatchLoopSkip2:
  528. ;    cmp.b #TLI_TYPE_TASKPATTERN,LN_TYPE(a0)
  529. ;    bne PatchLibraryMatchLoopSkip3
  530.  
  531. ;    movem.l d0-d2/a0/a1/a6,-(sp)
  532. ;    move.l LN_SIZE(a0),d1
  533. ;    move.l LN_NAME(a1),d2
  534. ;    move.l patchbase(pc),a6
  535. ;    move.l PB_DosBase(a6),a6
  536. ;    CALL MatchPatternNoCase
  537. ;    tst.l d0
  538. ;    movem.l (sp)+,d0-d2/a0/a1/a6
  539. ;    bne PatchLibraryMatchFound
  540.  
  541. ;PatchLibraryMatchLoopSkip3:
  542. ;    move.l (a0),a0
  543. ;    tst.l (a0)
  544. ;    bne PatchLibraryMatchLoop
  545.  
  546. ;PatchLibraryMatchListEmpty:
  547. ;    move.l (sp)+,a0
  548. ;    tst.l TL_Result2(a0)
  549. ;    rts
  550. ;PatchLibraryMatchFound:
  551. ;    move.l (sp)+,a0
  552. ;    tst.l TL_Result1(a0)
  553. ;    rts
  554. ;-----------------------------------------------------
  555.     XREF _AllocStackCached
  556. PatchLibraryStackAlloc:
  557. ;d0=StackSize
  558. ;a0=patch struct
  559.  
  560.     move.l d0,d2
  561.     move.l sysbase(pc),a6
  562.     move.l ThisTask(a6),a1
  563.  
  564.     move.l TC_SPLOWER(a1),d0
  565.     move.l TC_SPUPPER(a1),d1
  566.     cmp.l d0,d1
  567.     bhi PatchLibraryStackAllocSkip01
  568.     exg.l d0,d1
  569.  
  570.  
  571. PatchLibraryStackAllocSkip01:
  572.     cmp.l d0,a7                ;wenn a7 < SPLOWER
  573.     blo PatchLibraryStackAllocExit
  574.  
  575.     cmp.l d1,a7                ;wenn a7 > SPUPPER
  576.     bhi PatchLibraryStackAllocExit
  577.  
  578.     sub.l d0,d1
  579.     CMP.L d2,d1
  580.     BGE PatchLibraryStackAllocExit
  581.  
  582.  
  583.  
  584.     move.l d2,d0
  585.     jsr _AllocStackCached
  586.     tst.l d0
  587.     beq PatchLibraryStackAllocExit
  588.     move.l d0,a1
  589.  
  590.     lea.l 4*7(a7),a0    ;4Bytes * (Rücksprung + 6 register)
  591.     move.l a0,PST_OldStack(a1)
  592.  
  593.     move.l -(a0),-(a1)    ;6 registers
  594.     move.l -(a0),-(a1)
  595.     move.l -(a0),-(a1)
  596.     move.l -(a0),-(a1)
  597.     move.l -(a0),-(a1)
  598.     move.l -(a0),-(a1)
  599.     move.l -(a0),-(a1)    ;Rücksprung
  600.  
  601.     move.l d0,a0
  602.     move.l a1,PST_StackSwap+stk_Pointer(a0)
  603.     lea.l PST_StackSwap(a0),a0
  604.     jsr StackSwap(a6)
  605.  
  606. PatchLibraryStackAllocExit:
  607.     rts
  608. ;-----------------------------------------------------
  609. PatchLibraryXResult:
  610.     movem.l d0/a1,-(sp)
  611.     tst.l d0
  612.     beq PatchLibraryXResultExit
  613.     move.l d0,a1
  614.     move.l pxr_RegPattern(a1),d0
  615.     asr.l #2,d0
  616.     bcc PatchLibraryXResultSkip1
  617.     move.l pxr_RegA6(a1),a6
  618.  
  619. PatchLibraryXResultSkip1:
  620.     asr.l #1,d0
  621.     bcc PatchLibraryXResultSkip2
  622.     move.l pxr_RegA5(a1),a5
  623.  
  624. PatchLibraryXResultSkip2:
  625.     asr.l #1,d0
  626.     bcc PatchLibraryXResultSkip3
  627.     move.l pxr_RegA4(a1),a4
  628.  
  629. PatchLibraryXResultSkip3:
  630.     asr.l #1,d0
  631.     bcc PatchLibraryXResultSkip4
  632.     move.l pxr_RegA3(a1),a3
  633.  
  634. PatchLibraryXResultSkip4:
  635.     asr.l #1,d0
  636.     bcc PatchLibraryXResultSkip5
  637.     move.l pxr_RegA2(a1),a2
  638.  
  639. PatchLibraryXResultSkip5:
  640.     asr.l #1,d0
  641.     bcc PatchLibraryXResultSkip6
  642.     move.l pxr_RegA1(a1),4(a7)    ;Nur auf dem stack aendern
  643.  
  644. PatchLibraryXResultSkip6:
  645.     asr.l #1,d0
  646.     bcc PatchLibraryXResultSkip7
  647.     move.l pxr_RegA0(a1),a0
  648.  
  649. PatchLibraryXResultSkip7:
  650.     asr.l #1,d0
  651.     bcc PatchLibraryXResultSkip8
  652.     move.l pxr_RegD7(a1),d7
  653.  
  654. PatchLibraryXResultSkip8:
  655.     asr.l #1,d0
  656.     bcc PatchLibraryXResultSkip9
  657.     move.l pxr_RegD6(a1),d6
  658.  
  659. PatchLibraryXResultSkip9:
  660.     asr.l #1,d0
  661.     bcc PatchLibraryXResultSkip10
  662.     move.l pxr_RegD5(a1),d5
  663.  
  664. PatchLibraryXResultSkip10:
  665.     asr.l #1,d0
  666.     bcc PatchLibraryXResultSkip11
  667.     move.l pxr_RegD4(a1),d4
  668.  
  669. PatchLibraryXResultSkip11:
  670.     asr.l #1,d0
  671.     bcc PatchLibraryXResultSkip12
  672.     move.l pxr_RegD3(a1),d3
  673.  
  674. PatchLibraryXResultSkip12:
  675.     asr.l #1,d0
  676.     bcc PatchLibraryXResultSkip13
  677.     move.l pxr_RegD2(a1),d2
  678.  
  679. PatchLibraryXResultSkip13:
  680.     asr.l #1,d0
  681.     bcc PatchLibraryXResultSkip14
  682.     move.l pxr_RegD1(a1),d1
  683.  
  684. PatchLibraryXResultSkip14:
  685.     asr.l #1,d0
  686.     bcc PatchLibraryXResultSkip15
  687.     move.l pxr_RegD0(a1),(a7)    ;Nur auf dem stack aendern
  688.  
  689. PatchLibraryXResultSkip15:
  690.  
  691.     move.w pxr_FlowControl(a1),d0
  692.  
  693.     movem.l d0-d1/a0/a6,-(sp)
  694.     move.l patchbase(pc),a6
  695.     jsr PatchFreeVec(a6)
  696.     movem.l (sp)+,d0-d1/a0/a6
  697.  
  698. PatchLibraryXResultExit:
  699.     tst.w d0            ;bits muessen gesetzt sein
  700.     movem.l (sp)+,d0/a1
  701.     rts
  702. ;-----------------------------------------------------
  703. ;a0= pointer to patch struct
  704. ;SUPPORTED PATCHCODES: PCODE_GENERIC, PCODE_START, PCODE_ORIG, PCODE_END
  705. ;            PCODE_USER4
  706.     XDEF _InitPatchCode
  707. _InitPatchCode:
  708.     move.l a2,-(sp)
  709.     cmp.l #0,a0
  710.     beq InitPatchCodeExit
  711.     tst.l PS_PatchCode(a0)
  712.     beq InitPatchCodeExit
  713.     move.l a0,a2
  714.     move.l PS_PatchCode(a0),a1
  715.  
  716. InitPatchCodeSkip6:
  717.     cmp.b #PCODE_START,PS_PatchCodeType(a0)
  718.     bne InitPatchCodeSkip7
  719.  
  720.     lea.l PC2Offset_PatchStruct(a1),a0
  721.     move.l a2,(a0)
  722.     lea.l PC2Offset_Stack(a1),a0
  723.     move.l a0,PC6Offset_Stack1_Tst+2(a1)
  724.     lea.l PC2Offset_Usage(a1),a0
  725.     move.l a0,PC6Offset_Add+2(a1)
  726.     move.l a0,PC6Offset_Sub+2(a1)
  727.  
  728.     lea.l PC6Offset_JmpNext(a1),a0
  729.     move.l a0,PS_JmpNext(a2)
  730.  
  731.     lea.l PC6Offset_Add(a1),a0
  732.     move.l a0,PS_TestUsage1(a2)
  733.     lea.l PC6Offset_JmpNext(a1),a0
  734.     move.l a0,PS_TestUsage2(a2)
  735.  
  736.     bra InitPatchCodeExit
  737.  
  738. InitPatchCodeSkip7:
  739.     cmp.b #PCODE_ORIG,PS_PatchCodeType(a0)
  740.     bne InitPatchCodeSkip8
  741.  
  742.     lea.l PC2Offset_PatchStruct(a1),a0
  743.     move.l a2,(a0)
  744.     lea.l PC2Offset_Disable(a1),a0
  745.     move.l a0,PC7Offset_Tst0+2(a1)
  746.     lea.l PC2Offset_Usage(a1),a0
  747.     move.l a0,PC7Offset_Add+2(a1)
  748.     move.l a0,PC7Offset_Sub+2(a1)
  749.  
  750.     lea.l PC7Offset_Jsr(a1),a0
  751.     move.l a0,PS_Jsr(a2)
  752.     lea.l PC7Offset_JmpNext(a1),a0
  753.     move.l a0,PS_JmpNext(a2)
  754.  
  755.     lea.l PC7Offset_Add(a1),a0
  756.     move.l a0,PS_TestUsage1(a2)
  757.     lea.l PC7Offset_JmpNext(a1),a0
  758.     move.l a0,PS_TestUsage2(a2)
  759.  
  760.     bra InitPatchCodeExit
  761.  
  762. InitPatchCodeSkip8:
  763.     cmp.b #PCODE_END,PS_PatchCodeType(a0)
  764.     beq InitPatchCodeExit
  765.  
  766. InitPatchCodeSkip10:
  767.     cmp.b #PCODE_USER0,PS_PatchCodeType(a0)
  768.     bne InitPatchCodeSkip11
  769.  
  770.     lea.l PC2Offset_PatchStruct(a1),a0
  771.     move.l a2,(a0)
  772.     lea.l PC2Offset_Disable(a1),a0
  773.     move.l a0,PC10Offset_Tst0+2(a1)
  774.     lea.l PC2Offset_List(a1),a0
  775.     move.l a0,PC10Offset_Tst+2(a1)
  776.     lea.l PC2Offset_Usage(a1),a0
  777.     move.l a0,PC10Offset_Add+2(a1)
  778.     move.l a0,PC10Offset_Sub+2(a1)
  779.     move.l a0,PC10Offset_Sub2+2(a1)
  780.  
  781.     lea.l PC10Offset_JmpNext(a1),a0
  782.     move.l a0,PS_JmpNext(a2)
  783.     lea.l PC10Offset_JmpOrig(a1),a0
  784.     move.l a0,PS_JmpOrig(a2)
  785.     lea.l PC10Offset_Jsr(a1),a0
  786.     move.l a0,PS_Jsr(a2)
  787.  
  788.     lea.l PC10Offset_Add(a1),a0
  789.     move.l a0,PS_TestUsage1(a2)
  790.     lea.l PC10Offset_JmpOrig(a1),a0
  791.     move.l a0,PS_TestUsage2(a2)
  792.     lea.l PC10Offset_JmpNext(a1),a0
  793.     move.l a0,PS_TestUsage3(a2)
  794.  
  795.     bra InitPatchCodeExit
  796.  
  797. InitPatchCodeSkip11:
  798.     cmp.b #PCODE_USER1,PS_PatchCodeType(a0)
  799.     bne InitPatchCodeSkip12
  800.  
  801.     lea.l PC2Offset_PatchStruct(a1),a0
  802.     move.l a2,(a0)
  803.     lea.l PC2Offset_Disable(a1),a0
  804.     move.l a0,PC11Offset_Tst0+2(a1)
  805.     lea.l PC2Offset_List(a1),a0
  806.     move.l a0,PC11Offset_Tst+2(a1)
  807.     lea.l PC2Offset_Usage(a1),a0
  808.     move.l a0,PC11Offset_Add+2(a1)
  809.     move.l a0,PC11Offset_Sub+2(a1)
  810.     move.l a0,PC11Offset_Sub2+2(a1)
  811.  
  812.     lea.l PC11Offset_JmpNext(a1),a0
  813.     move.l a0,PS_JmpNext(a2)
  814.     lea.l PC11Offset_JmpOrig(a1),a0
  815.     move.l a0,PS_JmpOrig(a2)
  816.     lea.l PC11Offset_Jsr(a1),a0
  817.     move.l a0,PS_Jsr(a2)
  818.  
  819.     lea.l PC11Offset_Add(a1),a0
  820.     move.l a0,PS_TestUsage1(a2)
  821.     lea.l PC11Offset_JmpOrig(a1),a0
  822.     move.l a0,PS_TestUsage2(a2)
  823.     lea.l PC11Offset_JmpNext(a1),a0
  824.     move.l a0,PS_TestUsage3(a2)
  825.  
  826.     bra InitPatchCodeExit
  827.  
  828. InitPatchCodeSkip12:
  829.     cmp.b #PCODE_USER2,PS_PatchCodeType(a0)
  830.     bne InitPatchCodeSkip13
  831.  
  832.     lea.l PC2Offset_PatchStruct(a1),a0
  833.     move.l a2,(a0)
  834.     lea.l PC2Offset_Disable(a1),a0
  835.     move.l a0,PC12Offset_Tst0+2(a1)
  836.     lea.l PC2Offset_List(a1),a0
  837.     move.l a0,PC12Offset_Tst+2(a1)
  838.     lea.l PC2Offset_Usage(a1),a0
  839.     move.l a0,PC12Offset_Add+2(a1)
  840.     move.l a0,PC12Offset_Sub2+2(a1)
  841.  
  842.     lea.l PC12Offset_JmpNext(a1),a0
  843.     move.l a0,PS_JmpNext(a2)
  844.     lea.l PC12Offset_Jsr(a1),a0
  845.     move.l a0,PS_Jsr(a2)
  846.  
  847.     lea.l PC12Offset_Add(a1),a0
  848.     move.l a0,PS_TestUsage1(a2)
  849.     lea.l PC12Offset_JmpNext(a1),a0
  850.     move.l a0,PS_TestUsage2(a2)
  851.  
  852.     bra InitPatchCodeExit
  853.  
  854. InitPatchCodeSkip13:
  855.     cmp.b #PCODE_USER3,PS_PatchCodeType(a0)
  856.     bne InitPatchCodeSkip14
  857.  
  858.     lea.l PC2Offset_PatchStruct(a1),a0
  859.     move.l a2,(a0)
  860.     lea.l PC2Offset_Disable(a1),a0
  861.     move.l a0,PC13Offset_Tst0+2(a1)
  862.     lea.l PC2Offset_List(a1),a0
  863.     move.l a0,PC13Offset_Tst+2(a1)
  864.     lea.l PC2Offset_Usage(a1),a0
  865.     move.l a0,PC13Offset_Add+2(a1)
  866.     move.l a0,PC13Offset_Sub2+2(a1)
  867.  
  868.     lea.l PC13Offset_JmpNext(a1),a0
  869.     move.l a0,PS_JmpNext(a2)
  870.     lea.l PC13Offset_Jsr(a1),a0
  871.     move.l a0,PS_Jsr(a2)
  872.  
  873.     lea.l PC13Offset_Add(a1),a0
  874.     move.l a0,PS_TestUsage1(a2)
  875.     lea.l PC13Offset_JmpNext(a1),a0
  876.     move.l a0,PS_TestUsage2(a2)
  877.  
  878.     bra InitPatchCodeExit
  879.  
  880. InitPatchCodeSkip14:
  881.     cmp.b #PCODE_USER4,PS_PatchCodeType(a0)
  882.     bne InitPatchCodeSkip15
  883.  
  884.     lea.l PC2Offset_Disable(a1),a0
  885.     move.l a0,PC14Offset_Tst0+2(a1)
  886.     lea.l PC2Offset_List(a1),a0
  887.     move.l a0,PC14Offset_Tst+2(a1)
  888.     lea.l PC2Offset_Usage(a1),a0
  889.     move.l a0,PC14Offset_Add+2(a1)
  890.     move.l a0,PC14Offset_Sub+2(a1)
  891.     move.l a0,PC14Offset_Sub2+2(a1)
  892.  
  893.     lea.l PC14Offset_JmpNext(a1),a0
  894.     move.l a0,PS_JmpNext(a2)
  895.     lea.l PC14Offset_JmpOrig(a1),a0
  896.     move.l a0,PS_JmpOrig(a2)
  897.     lea.l PC14Offset_Jsr(a1),a0
  898.     move.l a0,PS_Jsr(a2)
  899.     lea.l PC14Offset_SystemEntry(a1),a0
  900.     move.l a0,PS_SystemEntry(a2)
  901.  
  902.     lea.l PC14Offset_Add(a1),a0
  903.     move.l a0,PS_TestUsage1(a2)
  904.     lea.l PC14Offset_JmpOrig(a1),a0
  905.     move.l a0,PS_TestUsage2(a2)
  906.     lea.l PC14Offset_JmpNext(a1),a0
  907.     move.l a0,PS_TestUsage3(a2)
  908.  
  909.     bra InitPatchCodeExit
  910.  
  911. InitPatchCodeSkip15:
  912.     cmp.b #PCODE_USER5,PS_PatchCodeType(a0)
  913.     bne InitPatchCodeSkip16
  914.  
  915.     lea.l PC2Offset_Disable(a1),a0
  916.     move.l a0,PC15Offset_Tst0+2(a1)
  917.     lea.l PC2Offset_List(a1),a0
  918.     move.l a0,PC15Offset_Tst+2(a1)
  919.     lea.l PC2Offset_Usage(a1),a0
  920.     move.l a0,PC15Offset_Add+2(a1)
  921.     move.l a0,PC15Offset_Sub+2(a1)
  922.     move.l a0,PC15Offset_Sub2+2(a1)
  923.  
  924.     lea.l PC15Offset_JmpNext(a1),a0
  925.     move.l a0,PS_JmpNext(a2)
  926.     lea.l PC15Offset_JmpOrig(a1),a0
  927.     move.l a0,PS_JmpOrig(a2)
  928.     lea.l PC15Offset_Jsr(a1),a0
  929.     move.l a0,PS_Jsr(a2)
  930.     lea.l PC15Offset_SystemEntry(a1),a0
  931.     move.l a0,PS_SystemEntry(a2)
  932.  
  933.     lea.l PC15Offset_Add(a1),a0
  934.     move.l a0,PS_TestUsage1(a2)
  935.     lea.l PC15Offset_JmpOrig(a1),a0
  936.     move.l a0,PS_TestUsage2(a2)
  937.     lea.l PC15Offset_JmpNext(a1),a0
  938.     move.l a0,PS_TestUsage3(a2)
  939.  
  940.     bra InitPatchCodeExit
  941.  
  942.  
  943. InitPatchCodeSkip16:
  944. ;PCODE_GENERIC is asumed for all unknown PatchCodeTypes
  945.     lea.l PC2Offset_PatchXResult(a1),a0
  946.     move.l a0,PC2Offset_Tst1_XResult+2(a1)
  947.     move.l a0,PC2Offset_Tst2_XResult+2(a1)
  948.     lea.l PC2Offset_PatchStruct(a1),a0
  949.     move.l a2,(a0)
  950.     lea.l PC2Offset_Disable(a1),a0
  951.     move.l a0,PC2Offset_Tst0+2(a1)
  952.     lea.l PC2Offset_List(a1),a0
  953.     move.l a0,PC2Offset_Tst+2(a1)
  954.     lea.l PC2Offset_Usage(a1),a0
  955.     move.l a0,PC2Offset_Add+2(a1)
  956.     move.l a0,PC2Offset_Sub+2(a1)
  957.     move.l a0,PC2Offset_Sub2+2(a1)
  958.  
  959.     lea.l PC2Offset_JmpNext(a1),a0
  960.     move.l a0,PS_JmpNext(a2)
  961.     lea.l PC2Offset_JmpOrig(a1),a0
  962.     move.l a0,PS_JmpOrig(a2)
  963.     lea.l PC2Offset_Jsr(a1),a0
  964.     move.l a0,PS_Jsr(a2)
  965.     lea.l PC2Offset_SystemEntry(a1),a0
  966.     move.l a0,PS_SystemEntry(a2)
  967.  
  968.     lea.l PC2Offset_Add(a1),a0
  969.     move.l a0,PS_TestUsage1(a2)
  970.     lea.l PC2Offset_JmpOrig(a1),a0
  971.     move.l a0,PS_TestUsage2(a2)
  972.     lea.l PC2Offset_JmpNext(a1),a0
  973.     move.l a0,PS_TestUsage3(a2)
  974.  
  975. InitPatchCodeExit:
  976.     move.l (sp)+,a2
  977.     rts
  978. ;---------------------------------------------------
  979. ;a0= pointer to stack
  980. ;a6= execbase
  981. ;Result: d0= PC or NULL, if not found
  982. ;This function is highly dependent on hardware
  983. ;Keep disabled, or result may not be valid
  984.     XDEF _GetPC
  985. _GetPC:
  986. GetPC:
  987.     moveq.l #0,d0
  988.     btst.b #7,AttnFlags+1(a6)
  989.     beq GetPCExit
  990.  
  991.     btst.b #7,AttnFlags+1(a6)    ;060 ? OK (currently there is no 060 without FPU)
  992.     beq GetPCSkip1
  993.  
  994.     tst.b 3(a0)
  995.     bne GetPC060Skip
  996.     move.l 12(a0),d0
  997.     bra GetPCExit
  998. GetPC060Skip:
  999.     move.l 48(a0),d0
  1000.     bra GetPCExit
  1001.  
  1002. GetPCSkip1:
  1003.     btst.b #3,AttnFlags+1(a6)    ;040 ?
  1004.     beq GetPCSkip2
  1005.     moveq.l #0,d0
  1006.     bra GetPCExit
  1007.  
  1008. GetPCSkip2:
  1009.     btst.b #2,AttnFlags+1(a6)    ;030 ?
  1010.     beq GetPCSkip3
  1011.     btst.b #4,AttnFlags+1(a6)    ;FPU ?
  1012.     beq GetPCSkip2NOFPU
  1013.  
  1014.     tst.b (a0)
  1015.     bne GetPC030Skip1
  1016.     move.l 12(a0),d0
  1017.     bra GetPCExit
  1018.  
  1019. GetPC030Skip1:
  1020.     cmp.b #$90,(a0)
  1021.     bne GetPC030Skip2
  1022.     move.l 120(a0),d0
  1023.     bra GetPCExit
  1024.  
  1025. GetPC030Skip2:
  1026.     move.l 108(a0),d0
  1027.     bra GetPCExit
  1028.  
  1029.  
  1030. GetPCSkip2NOFPU:
  1031.     moveq.l #0,d0
  1032.     bra GetPCExit
  1033.  
  1034. GetPCSkip3:
  1035.     btst.b #1,AttnFlags+1(a6)    ;020 ? OK
  1036.     beq GetPCSkip4
  1037.     move.l 2(a0),d0
  1038.     bra GetPCExit
  1039.  
  1040. GetPCSkip4:
  1041.     btst.b #0,AttnFlags+1(a6)    ;010 ? OK
  1042.     beq GetPCSkip5
  1043.     move.l 2(a0),d0
  1044.     bra GetPCExit
  1045.  
  1046. GetPCSkip5:
  1047.     move.l 2(a0),d0
  1048.  
  1049. GetPCExit:
  1050.     rts
  1051. ;----------------------------------------
  1052. ;a0= patch or NULL for no action
  1053. ;a1= pointer to 8Byte structure or NULL for no action
  1054. ;Result: structure contains size of template in the first 4Bytes
  1055. ;                        address of template in the second 4Bytes
  1056. ;SUPPORTED PATCHCODES: PCODE_GENERIC, PCODE_START, PCODE_ORIG, PCODE_END
  1057. ;            PCODE_USER0 - PCODE_USER5
  1058.     XDEF _GetPatchCodeTemplate
  1059. _GetPatchCodeTemplate:
  1060.     cmp.l #0,a0
  1061.     beq GetPatchCodeTemplateExit
  1062.     cmp.l #0,a1
  1063.     beq GetPatchCodeTemplateExit
  1064.  
  1065. GetPatchCodeTemplateSkip6:
  1066.     cmp.b #PCODE_START,PS_PatchCodeType(a0)
  1067.     bne GetPatchCodeTemplateSkip7
  1068.  
  1069.     move.l #PatchCode6End-PatchCode6Start,(a1)+
  1070.     lea.l PatchCode6Start(pc),a0
  1071.     move.l a0,(a1)+
  1072.     bra GetPatchCodeTemplateExit
  1073.  
  1074. GetPatchCodeTemplateSkip7:
  1075.     cmp.b #PCODE_ORIG,PS_PatchCodeType(a0)
  1076.     bne GetPatchCodeTemplateSkip8
  1077.  
  1078.     move.l #PatchCode7End-PatchCode7Start,(a1)+
  1079.     lea.l PatchCode7Start(pc),a0
  1080.     move.l a0,(a1)+
  1081.     bra GetPatchCodeTemplateExit
  1082.  
  1083. GetPatchCodeTemplateSkip8:
  1084.     cmp.b #PCODE_END,PS_PatchCodeType(a0)
  1085.     bne GetPatchCodeTemplateSkip10
  1086.  
  1087.     move.l #PatchCode8End-PatchCode8Start,(a1)+
  1088.     lea.l PatchCode8Start(pc),a0
  1089.     move.l a0,(a1)+
  1090.     bra GetPatchCodeTemplateExit
  1091.  
  1092. GetPatchCodeTemplateSkip10:
  1093.     cmp.b #PCODE_USER0,PS_PatchCodeType(a0)
  1094.     bne GetPatchCodeTemplateSkip11
  1095.  
  1096.     move.l #PatchCode10End-PatchCode10Start,(a1)+
  1097.     lea.l PatchCode10Start(pc),a0
  1098.     move.l a0,(a1)+
  1099.     bra GetPatchCodeTemplateExit
  1100.  
  1101. GetPatchCodeTemplateSkip11:
  1102.     cmp.b #PCODE_USER1,PS_PatchCodeType(a0)
  1103.     bne GetPatchCodeTemplateSkip12
  1104.  
  1105.     move.l #PatchCode11End-PatchCode11Start,(a1)+
  1106.     lea.l PatchCode11Start(pc),a0
  1107.     move.l a0,(a1)+
  1108.     bra GetPatchCodeTemplateExit
  1109.  
  1110. GetPatchCodeTemplateSkip12:
  1111.     cmp.b #PCODE_USER2,PS_PatchCodeType(a0)
  1112.     bne GetPatchCodeTemplateSkip13
  1113.  
  1114.     move.l #PatchCode12End-PatchCode12Start,(a1)+
  1115.     lea.l PatchCode12Start(pc),a0
  1116.     move.l a0,(a1)+
  1117.     bra GetPatchCodeTemplateExit
  1118.  
  1119. GetPatchCodeTemplateSkip13:
  1120.     cmp.b #PCODE_USER3,PS_PatchCodeType(a0)
  1121.     bne GetPatchCodeTemplateSkip14
  1122.  
  1123.     move.l #PatchCode13End-PatchCode13Start,(a1)+
  1124.     lea.l PatchCode13Start(pc),a0
  1125.     move.l a0,(a1)+
  1126.     bra GetPatchCodeTemplateExit
  1127.  
  1128. GetPatchCodeTemplateSkip14:
  1129.     cmp.b #PCODE_USER4,PS_PatchCodeType(a0)
  1130.     bne GetPatchCodeTemplateSkip15
  1131.  
  1132.     move.l #PatchCode14End-PatchCode14Start,(a1)+
  1133.     lea.l PatchCode14Start(pc),a0
  1134.     move.l a0,(a1)+
  1135.     bra GetPatchCodeTemplateExit
  1136.  
  1137.  
  1138. GetPatchCodeTemplateSkip15:
  1139.     cmp.b #PCODE_USER5,PS_PatchCodeType(a0)
  1140.     bne GetPatchCodeTemplateSkip16
  1141.  
  1142.     move.l #PatchCode15End-PatchCode15Start,(a1)+
  1143.     lea.l PatchCode15Start(pc),a0
  1144.     move.l a0,(a1)+
  1145.     bra GetPatchCodeTemplateExit
  1146.  
  1147. GetPatchCodeTemplateSkip16:
  1148.  
  1149. ;PCODE_GENERIC is asumed for all unknown PatchCodeTypes
  1150.     move.l #PatchCodeEnd-PatchCodeStart,(a1)+
  1151.     lea.l PatchCodeStart(pc),a0
  1152.     move.l a0,(a1)+
  1153.  
  1154.  
  1155. GetPatchCodeTemplateExit:
  1156.     rts
  1157. ;-----------------------------------------------------------------
  1158.     XDEF _SetupAsmEnv
  1159. ; a0 = pointer to patchbase
  1160. _SetupAsmEnv:
  1161.     lea.l patchbase(pc),a1
  1162.     move.l a0,(a1)
  1163.     lea.l sysbase(pc),a1
  1164.     move.l PB_SysBase(a0),(a1)
  1165.     rts
  1166. patchbase:    dc.l 0
  1167. sysbase:    dc.l 0
  1168.     END
  1169.